package com.liqi.common.core.domain;

import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.List;

@ApiModel("分页数据")
@Data
public class PageData<T> {

    @ApiModelProperty("页码")
    private int pageNum;

    @ApiModelProperty("页大小")
    private int pageSize;

    @ApiModelProperty("记录数")
    private int size;

    @ApiModelProperty("总记录数")
    private long total;

    @ApiModelProperty("数据")
    private List<T> list;

    public PageData() {
    }

    public PageData(PageInfo<T> pageInfo) {
        this.pageNum = pageInfo.getPageNum();
        this.pageSize = pageInfo.getPageSize();
        this.size = pageInfo.getSize();
        this.total = pageInfo.getTotal();
        this.list = pageInfo.getList();
    }

    public static <T> PageData<T> page(PageInfo<T> pageInfo) {
        return new PageData<>(pageInfo);
    }
}
